package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AppCompatActivity;

public class ThirdActivity extends BaseActivity implements View.OnClickListener {

    private RadioButton t2;
    private  int score2 = 0;
    private  int score1 = 0;
    private RadioGroup radiogroup;
    private Button prev1;
    private Button next1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.third_layout);
        initView();
        // 获取意图对象
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        score1 = bundle.getInt("score_1");

//        Toast.makeText(ThirdActivity.this, "第一题的所得分数为" + score_1, Toast.LENGTH_SHORT).show();
    }

    private void initView() {
        t2 = (RadioButton) findViewById(R.id.t2);

        radiogroup = (RadioGroup) findViewById(R.id.radiogroup);
        //调用setOnCheckedChangeListener来对RadioGroup进行监听的代码
        radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == t2.getId()) {
                    score2 = 20;
                }
            }

        });
        prev1 = (Button) findViewById(R.id.prev1);
        prev1.setOnClickListener(this);
        next1 = (Button) findViewById(R.id.next1);
        next1.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.prev1:
                Intent intent = new Intent(ThirdActivity.this,SecondActivity.class);
                startActivity(intent);
                break;
            case R.id.next1:
                //创建意图对象
                Intent intent2 = new Intent(ThirdActivity.this, FourthActivity.class);
//        传递数据
                Bundle bundle = new Bundle();
                bundle.putInt("score2", score1 + score2);
                intent2.putExtras(bundle);
                //激活意图
                startActivity(intent2);
                break;
        }
    }
}